/*
 Navicat Premium Data Transfer

 Source Server         : 机房sqlserver
 Source Server Type    : SQL Server
 Source Server Version : 15002000 (15.00.2000)
 Source Host           : 192.168.0.208:1433
 Source Catalog        : fpe_production
 Source Schema         : dbo

 Target Server Type    : SQL Server
 Target Server Version : 15002000 (15.00.2000)
 File Encoding         : 65001

 Date: 24/03/2023 11:50:11
*/


-- ----------------------------
-- Table structure for all_machine
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[all_machine]') AND type IN ('U'))
	DROP TABLE [dbo].[all_machine]
GO

CREATE TABLE [dbo].[all_machine] (
  [id] int  IDENTITY(1,1) NOT NULL,
  [machine_info_id] int  NULL,
  [machine_num] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [status] bit DEFAULT 1 NULL,
  [create_time] datetime DEFAULT getdate() NULL,
  [machine_info_name] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [dept_id] int  NULL
)
GO

ALTER TABLE [dbo].[all_machine] SET (LOCK_ESCALATION = TABLE)
GO

EXEC sp_addextendedproperty
'MS_Description', N'所属机器种类',
'SCHEMA', N'dbo',
'TABLE', N'all_machine',
'COLUMN', N'machine_info_id'
GO

EXEC sp_addextendedproperty
'MS_Description', N'机器编号',
'SCHEMA', N'dbo',
'TABLE', N'all_machine',
'COLUMN', N'machine_num'
GO

EXEC sp_addextendedproperty
'MS_Description', N'机器状态（0代表不可用，1代表可用）',
'SCHEMA', N'dbo',
'TABLE', N'all_machine',
'COLUMN', N'status'
GO

EXEC sp_addextendedproperty
'MS_Description', N'加入时间',
'SCHEMA', N'dbo',
'TABLE', N'all_machine',
'COLUMN', N'create_time'
GO

EXEC sp_addextendedproperty
'MS_Description', N'机种名称',
'SCHEMA', N'dbo',
'TABLE', N'all_machine',
'COLUMN', N'machine_info_name'
GO

EXEC sp_addextendedproperty
'MS_Description', N'所属部门',
'SCHEMA', N'dbo',
'TABLE', N'all_machine',
'COLUMN', N'dept_id'
GO


-- ----------------------------
-- Table structure for check_info
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[check_info]') AND type IN ('U'))
	DROP TABLE [dbo].[check_info]
GO

CREATE TABLE [dbo].[check_info] (
  [id] int  IDENTITY(1,1) NOT NULL,
  [order_num] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [checker] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [is_pass] bit  NULL,
  [checker_no] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [create_time] datetime DEFAULT getdate() NULL,
  [ng_reason] varchar(3000) COLLATE Chinese_PRC_CI_AI DEFAULT '无' NULL
)
GO

ALTER TABLE [dbo].[check_info] SET (LOCK_ESCALATION = TABLE)
GO


-- ----------------------------
-- Table structure for complement_info
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[complement_info]') AND type IN ('U'))
	DROP TABLE [dbo].[complement_info]
GO

CREATE TABLE [dbo].[complement_info] (
  [id] int  IDENTITY(1,1) NOT NULL,
  [order_num] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [now_process] int  NULL,
  [d_value] int  NULL,
  [before_value] int  NULL,
  [complement_user] int  NULL,
  [complement_time] datetime DEFAULT getdate() NULL
)
GO

ALTER TABLE [dbo].[complement_info] SET (LOCK_ESCALATION = TABLE)
GO

EXEC sp_addextendedproperty
'MS_Description', N'补数工单号',
'SCHEMA', N'dbo',
'TABLE', N'complement_info',
'COLUMN', N'order_num'
GO

EXEC sp_addextendedproperty
'MS_Description', N'补数工序id',
'SCHEMA', N'dbo',
'TABLE', N'complement_info',
'COLUMN', N'now_process'
GO

EXEC sp_addextendedproperty
'MS_Description', N'补数差值',
'SCHEMA', N'dbo',
'TABLE', N'complement_info',
'COLUMN', N'd_value'
GO

EXEC sp_addextendedproperty
'MS_Description', N'补数前数值',
'SCHEMA', N'dbo',
'TABLE', N'complement_info',
'COLUMN', N'before_value'
GO

EXEC sp_addextendedproperty
'MS_Description', N'补数人id',
'SCHEMA', N'dbo',
'TABLE', N'complement_info',
'COLUMN', N'complement_user'
GO

EXEC sp_addextendedproperty
'MS_Description', N'补数时间',
'SCHEMA', N'dbo',
'TABLE', N'complement_info',
'COLUMN', N'complement_time'
GO


-- ----------------------------
-- Table structure for core_library
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[core_library]') AND type IN ('U'))
	DROP TABLE [dbo].[core_library]
GO

CREATE TABLE [dbo].[core_library] (
  [id] int  IDENTITY(1,1) NOT NULL,
  [core_pin] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [dept_id] int  NULL,
  [create_time] datetime DEFAULT getdate() NULL,
  [core_status] bit DEFAULT 1 NULL,
  [core_code] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL
)
GO

ALTER TABLE [dbo].[core_library] SET (LOCK_ESCALATION = TABLE)
GO

EXEC sp_addextendedproperty
'MS_Description', N'core品名',
'SCHEMA', N'dbo',
'TABLE', N'core_library',
'COLUMN', N'core_pin'
GO

EXEC sp_addextendedproperty
'MS_Description', N'所属部门',
'SCHEMA', N'dbo',
'TABLE', N'core_library',
'COLUMN', N'dept_id'
GO

EXEC sp_addextendedproperty
'MS_Description', N'创建时间',
'SCHEMA', N'dbo',
'TABLE', N'core_library',
'COLUMN', N'create_time'
GO

EXEC sp_addextendedproperty
'MS_Description', N'状态,0表示停用，1表示在产',
'SCHEMA', N'dbo',
'TABLE', N'core_library',
'COLUMN', N'core_status'
GO

EXEC sp_addextendedproperty
'MS_Description', N'core代码（唯一）',
'SCHEMA', N'dbo',
'TABLE', N'core_library',
'COLUMN', N'core_code'
GO


-- ----------------------------
-- Table structure for cpk_info
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[cpk_info]') AND type IN ('U'))
	DROP TABLE [dbo].[cpk_info]
GO

CREATE TABLE [dbo].[cpk_info] (
  [id] int  IDENTITY(1,1) NOT NULL,
  [pin_name] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [create_time] datetime DEFAULT getdate() NULL,
  [ca] float(53)  NULL,
  [cp] float(53)  NULL,
  [cpk] float(53)  NULL,
  [machine_num] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [worker_no] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [order_num] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [dept_id] int  NULL,
  [s_data] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [lsl] float(53)  NULL,
  [usl] float(53)  NULL
)
GO

ALTER TABLE [dbo].[cpk_info] SET (LOCK_ESCALATION = TABLE)
GO

EXEC sp_addextendedproperty
'MS_Description', N'计算的产品',
'SCHEMA', N'dbo',
'TABLE', N'cpk_info',
'COLUMN', N'pin_name'
GO

EXEC sp_addextendedproperty
'MS_Description', N'计算时间',
'SCHEMA', N'dbo',
'TABLE', N'cpk_info',
'COLUMN', N'create_time'
GO

EXEC sp_addextendedproperty
'MS_Description', N'ca值',
'SCHEMA', N'dbo',
'TABLE', N'cpk_info',
'COLUMN', N'ca'
GO

EXEC sp_addextendedproperty
'MS_Description', N'cp值',
'SCHEMA', N'dbo',
'TABLE', N'cpk_info',
'COLUMN', N'cp'
GO

EXEC sp_addextendedproperty
'MS_Description', N'cpk',
'SCHEMA', N'dbo',
'TABLE', N'cpk_info',
'COLUMN', N'cpk'
GO

EXEC sp_addextendedproperty
'MS_Description', N'lot号',
'SCHEMA', N'dbo',
'TABLE', N'cpk_info',
'COLUMN', N'order_num'
GO


-- ----------------------------
-- Table structure for delete_info
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[delete_info]') AND type IN ('U'))
	DROP TABLE [dbo].[delete_info]
GO

CREATE TABLE [dbo].[delete_info] (
  [id] int  IDENTITY(1,1) NOT NULL,
  [delete_process_id] int  NULL,
  [delete_process_name] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [delete_worker_name] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [delete_worker_no] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [delete_time] datetime DEFAULT getdate() NULL,
  [order_num] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL
)
GO

ALTER TABLE [dbo].[delete_info] SET (LOCK_ESCALATION = TABLE)
GO

EXEC sp_addextendedproperty
'MS_Description', N'删除工序id',
'SCHEMA', N'dbo',
'TABLE', N'delete_info',
'COLUMN', N'delete_process_id'
GO

EXEC sp_addextendedproperty
'MS_Description', N'删除工序名',
'SCHEMA', N'dbo',
'TABLE', N'delete_info',
'COLUMN', N'delete_process_name'
GO

EXEC sp_addextendedproperty
'MS_Description', N'删除人',
'SCHEMA', N'dbo',
'TABLE', N'delete_info',
'COLUMN', N'delete_worker_name'
GO

EXEC sp_addextendedproperty
'MS_Description', N'删除人工号',
'SCHEMA', N'dbo',
'TABLE', N'delete_info',
'COLUMN', N'delete_worker_no'
GO

EXEC sp_addextendedproperty
'MS_Description', N'删除时间',
'SCHEMA', N'dbo',
'TABLE', N'delete_info',
'COLUMN', N'delete_time'
GO

EXEC sp_addextendedproperty
'MS_Description', N'删除工单号',
'SCHEMA', N'dbo',
'TABLE', N'delete_info',
'COLUMN', N'order_num'
GO


-- ----------------------------
-- Table structure for in_storage
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[in_storage]') AND type IN ('U'))
	DROP TABLE [dbo].[in_storage]
GO

CREATE TABLE [dbo].[in_storage] (
  [id] int  IDENTITY(1,1) NOT NULL,
  [machine_num] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [lot_list] varchar(1000) COLLATE Chinese_PRC_CI_AI  NULL,
  [pin_id] int  NULL,
  [total_amounts] int  NULL,
  [create_time] datetime DEFAULT getdate() NULL,
  [dept_id] int  NULL,
  [in_num] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [now_amounts] int  NULL
)
GO

ALTER TABLE [dbo].[in_storage] SET (LOCK_ESCALATION = TABLE)
GO

EXEC sp_addextendedproperty
'MS_Description', N'机台号',
'SCHEMA', N'dbo',
'TABLE', N'in_storage',
'COLUMN', N'machine_num'
GO

EXEC sp_addextendedproperty
'MS_Description', N'来源lot',
'SCHEMA', N'dbo',
'TABLE', N'in_storage',
'COLUMN', N'lot_list'
GO

EXEC sp_addextendedproperty
'MS_Description', N'产品Id',
'SCHEMA', N'dbo',
'TABLE', N'in_storage',
'COLUMN', N'pin_id'
GO

EXEC sp_addextendedproperty
'MS_Description', N'总数',
'SCHEMA', N'dbo',
'TABLE', N'in_storage',
'COLUMN', N'total_amounts'
GO

EXEC sp_addextendedproperty
'MS_Description', N'入库时间',
'SCHEMA', N'dbo',
'TABLE', N'in_storage',
'COLUMN', N'create_time'
GO

EXEC sp_addextendedproperty
'MS_Description', N'部门id',
'SCHEMA', N'dbo',
'TABLE', N'in_storage',
'COLUMN', N'dept_id'
GO

EXEC sp_addextendedproperty
'MS_Description', N'入库单编号',
'SCHEMA', N'dbo',
'TABLE', N'in_storage',
'COLUMN', N'in_num'
GO

EXEC sp_addextendedproperty
'MS_Description', N'当前数量',
'SCHEMA', N'dbo',
'TABLE', N'in_storage',
'COLUMN', N'now_amounts'
GO


-- ----------------------------
-- Table structure for machine_info
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[machine_info]') AND type IN ('U'))
	DROP TABLE [dbo].[machine_info]
GO

CREATE TABLE [dbo].[machine_info] (
  [id] int  IDENTITY(1,1) NOT NULL,
  [machine_model] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [dept_id] int  NULL,
  [create_time] datetime DEFAULT getdate() NULL,
  [rx_type] bit  NULL
)
GO

ALTER TABLE [dbo].[machine_info] SET (LOCK_ESCALATION = TABLE)
GO

EXEC sp_addextendedproperty
'MS_Description', N'机器型号，类型',
'SCHEMA', N'dbo',
'TABLE', N'machine_info',
'COLUMN', N'machine_model'
GO

EXEC sp_addextendedproperty
'MS_Description', N'所属部门',
'SCHEMA', N'dbo',
'TABLE', N'machine_info',
'COLUMN', N'dept_id'
GO

EXEC sp_addextendedproperty
'MS_Description', N'加入时间',
'SCHEMA', N'dbo',
'TABLE', N'machine_info',
'COLUMN', N'create_time'
GO


-- ----------------------------
-- Table structure for out_storage
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[out_storage]') AND type IN ('U'))
	DROP TABLE [dbo].[out_storage]
GO

CREATE TABLE [dbo].[out_storage] (
  [id] int  IDENTITY(1,1) NOT NULL,
  [out_amounts] int  NULL,
  [in_num] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [out_num] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [create_time] datetime DEFAULT getdate() NULL,
  [dept_id] int  NULL,
  [pin_id] int  NULL
)
GO

ALTER TABLE [dbo].[out_storage] SET (LOCK_ESCALATION = TABLE)
GO

EXEC sp_addextendedproperty
'MS_Description', N'出库数量',
'SCHEMA', N'dbo',
'TABLE', N'out_storage',
'COLUMN', N'out_amounts'
GO

EXEC sp_addextendedproperty
'MS_Description', N'入库单号',
'SCHEMA', N'dbo',
'TABLE', N'out_storage',
'COLUMN', N'in_num'
GO

EXEC sp_addextendedproperty
'MS_Description', N'出库单号',
'SCHEMA', N'dbo',
'TABLE', N'out_storage',
'COLUMN', N'out_num'
GO

EXEC sp_addextendedproperty
'MS_Description', N'出库时间',
'SCHEMA', N'dbo',
'TABLE', N'out_storage',
'COLUMN', N'create_time'
GO

EXEC sp_addextendedproperty
'MS_Description', N'部门id',
'SCHEMA', N'dbo',
'TABLE', N'out_storage',
'COLUMN', N'dept_id'
GO

EXEC sp_addextendedproperty
'MS_Description', N'产品id',
'SCHEMA', N'dbo',
'TABLE', N'out_storage',
'COLUMN', N'pin_id'
GO


-- ----------------------------
-- Table structure for parent_order
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[parent_order]') AND type IN ('U'))
	DROP TABLE [dbo].[parent_order]
GO

CREATE TABLE [dbo].[parent_order] (
  [id] int  IDENTITY(1,1) NOT NULL,
  [total_amount] int  NULL,
  [lot_no] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [pin_id] int  NULL,
  [accept_amount] int  NULL,
  [children_num] int  NULL,
  [process] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [product_type] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [material_code] varchar(255) COLLATE Chinese_PRC_CI_AI DEFAULT '-' NULL,
  [material_name] varchar(255) COLLATE Chinese_PRC_CI_AI DEFAULT '-' NULL,
  [material_model] varchar(255) COLLATE Chinese_PRC_CI_AI DEFAULT '-' NULL,
  [unit] varchar(255) COLLATE Chinese_PRC_CI_AI DEFAULT '个' NULL,
  [workshop] varchar(255) COLLATE Chinese_PRC_CI_AI DEFAULT '生产' NULL,
  [create_by] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [order_dept] int  NULL,
  [create_time] datetime DEFAULT getdate() NULL,
  [is_over] bit DEFAULT 0 NULL,
  [amount] int DEFAULT 0 NULL,
  [bad_amount] int DEFAULT 0 NULL,
  [core_id] int DEFAULT 0 NULL
)
GO

ALTER TABLE [dbo].[parent_order] SET (LOCK_ESCALATION = TABLE)
GO

EXEC sp_addextendedproperty
'MS_Description', N'总数',
'SCHEMA', N'dbo',
'TABLE', N'parent_order',
'COLUMN', N'total_amount'
GO

EXEC sp_addextendedproperty
'MS_Description', N'lotno,用于生成orderNum',
'SCHEMA', N'dbo',
'TABLE', N'parent_order',
'COLUMN', N'lot_no'
GO

EXEC sp_addextendedproperty
'MS_Description', N'产品id',
'SCHEMA', N'dbo',
'TABLE', N'parent_order',
'COLUMN', N'pin_id'
GO

EXEC sp_addextendedproperty
'MS_Description', N'每个子工单接收数量（计划数量）',
'SCHEMA', N'dbo',
'TABLE', N'parent_order',
'COLUMN', N'accept_amount'
GO

EXEC sp_addextendedproperty
'MS_Description', N'产生子工单数量',
'SCHEMA', N'dbo',
'TABLE', N'parent_order',
'COLUMN', N'children_num'
GO

EXEC sp_addextendedproperty
'MS_Description', N'所需工序',
'SCHEMA', N'dbo',
'TABLE', N'parent_order',
'COLUMN', N'process'
GO

EXEC sp_addextendedproperty
'MS_Description', N'产品类型',
'SCHEMA', N'dbo',
'TABLE', N'parent_order',
'COLUMN', N'product_type'
GO

EXEC sp_addextendedproperty
'MS_Description', N'物料编码',
'SCHEMA', N'dbo',
'TABLE', N'parent_order',
'COLUMN', N'material_code'
GO

EXEC sp_addextendedproperty
'MS_Description', N'物料名称',
'SCHEMA', N'dbo',
'TABLE', N'parent_order',
'COLUMN', N'material_name'
GO

EXEC sp_addextendedproperty
'MS_Description', N'物料型号规格',
'SCHEMA', N'dbo',
'TABLE', N'parent_order',
'COLUMN', N'material_model'
GO

EXEC sp_addextendedproperty
'MS_Description', N'单位',
'SCHEMA', N'dbo',
'TABLE', N'parent_order',
'COLUMN', N'unit'
GO

EXEC sp_addextendedproperty
'MS_Description', N'下达车间',
'SCHEMA', N'dbo',
'TABLE', N'parent_order',
'COLUMN', N'workshop'
GO

EXEC sp_addextendedproperty
'MS_Description', N'创建人',
'SCHEMA', N'dbo',
'TABLE', N'parent_order',
'COLUMN', N'create_by'
GO

EXEC sp_addextendedproperty
'MS_Description', N'所属部门',
'SCHEMA', N'dbo',
'TABLE', N'parent_order',
'COLUMN', N'order_dept'
GO

EXEC sp_addextendedproperty
'MS_Description', N'创建时间',
'SCHEMA', N'dbo',
'TABLE', N'parent_order',
'COLUMN', N'create_time'
GO

EXEC sp_addextendedproperty
'MS_Description', N'1代表结束，0代表未结束',
'SCHEMA', N'dbo',
'TABLE', N'parent_order',
'COLUMN', N'is_over'
GO

EXEC sp_addextendedproperty
'MS_Description', N'子工单已结算良品数',
'SCHEMA', N'dbo',
'TABLE', N'parent_order',
'COLUMN', N'amount'
GO

EXEC sp_addextendedproperty
'MS_Description', N'子工单已结算不良数',
'SCHEMA', N'dbo',
'TABLE', N'parent_order',
'COLUMN', N'bad_amount'
GO

EXEC sp_addextendedproperty
'MS_Description', N'core品名id',
'SCHEMA', N'dbo',
'TABLE', N'parent_order',
'COLUMN', N'core_id'
GO


-- ----------------------------
-- Table structure for pin_library
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[pin_library]') AND type IN ('U'))
	DROP TABLE [dbo].[pin_library]
GO

CREATE TABLE [dbo].[pin_library] (
  [id] int  IDENTITY(1,1) NOT NULL,
  [pin_name] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [dept_id] int  NULL,
  [create_time] datetime DEFAULT getdate() NULL,
  [create_by] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [process] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [product_type] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [product_status] bit DEFAULT 1 NULL,
  [erp_id] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL
)
GO

ALTER TABLE [dbo].[pin_library] SET (LOCK_ESCALATION = TABLE)
GO

EXEC sp_addextendedproperty
'MS_Description', N'品名/产品名,对应erp的产品型号名',
'SCHEMA', N'dbo',
'TABLE', N'pin_library',
'COLUMN', N'pin_name'
GO

EXEC sp_addextendedproperty
'MS_Description', N'所属部门',
'SCHEMA', N'dbo',
'TABLE', N'pin_library',
'COLUMN', N'dept_id'
GO

EXEC sp_addextendedproperty
'MS_Description', N'创建时间',
'SCHEMA', N'dbo',
'TABLE', N'pin_library',
'COLUMN', N'create_time'
GO

EXEC sp_addextendedproperty
'MS_Description', N'创建人工号',
'SCHEMA', N'dbo',
'TABLE', N'pin_library',
'COLUMN', N'create_by'
GO

EXEC sp_addextendedproperty
'MS_Description', N'所需工序',
'SCHEMA', N'dbo',
'TABLE', N'pin_library',
'COLUMN', N'process'
GO

EXEC sp_addextendedproperty
'MS_Description', N'产品类型',
'SCHEMA', N'dbo',
'TABLE', N'pin_library',
'COLUMN', N'product_type'
GO

EXEC sp_addextendedproperty
'MS_Description', N'0表示停产，1表示在产',
'SCHEMA', N'dbo',
'TABLE', N'pin_library',
'COLUMN', N'product_status'
GO

EXEC sp_addextendedproperty
'MS_Description', N'erp对应物料id',
'SCHEMA', N'dbo',
'TABLE', N'pin_library',
'COLUMN', N'erp_id'
GO


-- ----------------------------
-- Table structure for process_condition
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[process_condition]') AND type IN ('U'))
	DROP TABLE [dbo].[process_condition]
GO

CREATE TABLE [dbo].[process_condition] (
  [id] int  IDENTITY(1,1) NOT NULL,
  [pin_id] int  NULL,
  [dept_id] int  NULL,
  [create_time] datetime DEFAULT getdate() NULL,
  [mould_path] varchar(6000) COLLATE Chinese_PRC_CI_AI  NULL,
  [core_ids] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [machine_info_id] int DEFAULT 0 NULL,
  [mould_num] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [mould_key] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [mould_name] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [mould_status] varchar(1) COLLATE Chinese_PRC_CI_AI DEFAULT '0' NULL
)
GO

ALTER TABLE [dbo].[process_condition] SET (LOCK_ESCALATION = TABLE)
GO

EXEC sp_addextendedproperty
'MS_Description', N'所属产品id,0表示全产品通用',
'SCHEMA', N'dbo',
'TABLE', N'process_condition',
'COLUMN', N'pin_id'
GO

EXEC sp_addextendedproperty
'MS_Description', N'部门id',
'SCHEMA', N'dbo',
'TABLE', N'process_condition',
'COLUMN', N'dept_id'
GO

EXEC sp_addextendedproperty
'MS_Description', N'建立时间',
'SCHEMA', N'dbo',
'TABLE', N'process_condition',
'COLUMN', N'create_time'
GO

EXEC sp_addextendedproperty
'MS_Description', N'模板路径',
'SCHEMA', N'dbo',
'TABLE', N'process_condition',
'COLUMN', N'mould_path'
GO

EXEC sp_addextendedproperty
'MS_Description', N'适用core，0表示core通用',
'SCHEMA', N'dbo',
'TABLE', N'process_condition',
'COLUMN', N'core_ids'
GO

EXEC sp_addextendedproperty
'MS_Description', N'适应机台,0代表机台通用',
'SCHEMA', N'dbo',
'TABLE', N'process_condition',
'COLUMN', N'machine_info_id'
GO

EXEC sp_addextendedproperty
'MS_Description', N'模板编号',
'SCHEMA', N'dbo',
'TABLE', N'process_condition',
'COLUMN', N'mould_num'
GO

EXEC sp_addextendedproperty
'MS_Description', N'模板控制码',
'SCHEMA', N'dbo',
'TABLE', N'process_condition',
'COLUMN', N'mould_key'
GO

EXEC sp_addextendedproperty
'MS_Description', N'模板名',
'SCHEMA', N'dbo',
'TABLE', N'process_condition',
'COLUMN', N'mould_name'
GO

EXEC sp_addextendedproperty
'MS_Description', N'0代表未上传模板文件，1代表在用，2代表停用',
'SCHEMA', N'dbo',
'TABLE', N'process_condition',
'COLUMN', N'mould_status'
GO


-- ----------------------------
-- Table structure for process_info
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[process_info]') AND type IN ('U'))
	DROP TABLE [dbo].[process_info]
GO

CREATE TABLE [dbo].[process_info] (
  [id] int  IDENTITY(1,1) NOT NULL,
  [process_dept] int  NULL,
  [work_center] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [workshop] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [process_name] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [process_explain] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [process_code] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [machine] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [is_consume] bit  NULL
)
GO

ALTER TABLE [dbo].[process_info] SET (LOCK_ESCALATION = TABLE)
GO

EXEC sp_addextendedproperty
'MS_Description', N'工序id',
'SCHEMA', N'dbo',
'TABLE', N'process_info',
'COLUMN', N'id'
GO

EXEC sp_addextendedproperty
'MS_Description', N'加工部门id',
'SCHEMA', N'dbo',
'TABLE', N'process_info',
'COLUMN', N'process_dept'
GO

EXEC sp_addextendedproperty
'MS_Description', N'工作中心',
'SCHEMA', N'dbo',
'TABLE', N'process_info',
'COLUMN', N'work_center'
GO

EXEC sp_addextendedproperty
'MS_Description', N'加工车间 ',
'SCHEMA', N'dbo',
'TABLE', N'process_info',
'COLUMN', N'workshop'
GO

EXEC sp_addextendedproperty
'MS_Description', N'工序名称',
'SCHEMA', N'dbo',
'TABLE', N'process_info',
'COLUMN', N'process_name'
GO

EXEC sp_addextendedproperty
'MS_Description', N'工序说明',
'SCHEMA', N'dbo',
'TABLE', N'process_info',
'COLUMN', N'process_explain'
GO

EXEC sp_addextendedproperty
'MS_Description', N'工序控制码',
'SCHEMA', N'dbo',
'TABLE', N'process_info',
'COLUMN', N'process_code'
GO

EXEC sp_addextendedproperty
'MS_Description', N'所需机器',
'SCHEMA', N'dbo',
'TABLE', N'process_info',
'COLUMN', N'machine'
GO

EXEC sp_addextendedproperty
'MS_Description', N'是否为耗材工序,0代表不耗材，1代表耗材',
'SCHEMA', N'dbo',
'TABLE', N'process_info',
'COLUMN', N'is_consume'
GO


-- ----------------------------
-- Table structure for re_order
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[re_order]') AND type IN ('U'))
	DROP TABLE [dbo].[re_order]
GO

CREATE TABLE [dbo].[re_order] (
  [id] int  IDENTITY(1,1) NOT NULL,
  [old_lot] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [re_lot] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [create_time] datetime DEFAULT getdate() NULL,
  [creater] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [pin_id] int  NULL,
  [is_down] bit DEFAULT 0 NULL,
  [status] char(1) COLLATE Chinese_PRC_CI_AI DEFAULT '0' NULL,
  [dept_id] int  NULL,
  [down_worker] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL
)
GO

ALTER TABLE [dbo].[re_order] SET (LOCK_ESCALATION = TABLE)
GO

EXEC sp_addextendedproperty
'MS_Description', N'原工单号',
'SCHEMA', N'dbo',
'TABLE', N're_order',
'COLUMN', N'old_lot'
GO

EXEC sp_addextendedproperty
'MS_Description', N'返工单号',
'SCHEMA', N'dbo',
'TABLE', N're_order',
'COLUMN', N're_lot'
GO

EXEC sp_addextendedproperty
'MS_Description', N'创建时间',
'SCHEMA', N'dbo',
'TABLE', N're_order',
'COLUMN', N'create_time'
GO

EXEC sp_addextendedproperty
'MS_Description', N'创建人工号',
'SCHEMA', N'dbo',
'TABLE', N're_order',
'COLUMN', N'creater'
GO

EXEC sp_addextendedproperty
'MS_Description', N'产品id',
'SCHEMA', N'dbo',
'TABLE', N're_order',
'COLUMN', N'pin_id'
GO

EXEC sp_addextendedproperty
'MS_Description', N'1代表已打印，0代表未打印',
'SCHEMA', N'dbo',
'TABLE', N're_order',
'COLUMN', N'is_down'
GO

EXEC sp_addextendedproperty
'MS_Description', N'1代表生效，0代表未处理,2代表作废',
'SCHEMA', N'dbo',
'TABLE', N're_order',
'COLUMN', N'status'
GO

EXEC sp_addextendedproperty
'MS_Description', N'部门id',
'SCHEMA', N'dbo',
'TABLE', N're_order',
'COLUMN', N'dept_id'
GO

EXEC sp_addextendedproperty
'MS_Description', N'列印人',
'SCHEMA', N'dbo',
'TABLE', N're_order',
'COLUMN', N'down_worker'
GO


-- ----------------------------
-- Table structure for report_order
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[report_order]') AND type IN ('U'))
	DROP TABLE [dbo].[report_order]
GO

CREATE TABLE [dbo].[report_order] (
  [id] int  IDENTITY(1,1) NOT NULL,
  [order_num] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [reporter] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [report_process] int  NULL,
  [report_amount] int  NULL,
  [create_time] datetime DEFAULT getdate() NULL,
  [process_worker] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [is_over] bit  NULL,
  [bad_amount] int  NULL,
  [worker_no] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [is_missing] bit  NULL,
  [missing_amount] int DEFAULT 0 NULL,
  [machine_num] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [stuff_num] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [core_num] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [dept_id] int  NULL,
  [supply_amount] int DEFAULT 0 NULL,
  [pin_id] int  NULL
)
GO

ALTER TABLE [dbo].[report_order] SET (LOCK_ESCALATION = TABLE)
GO

EXEC sp_addextendedproperty
'MS_Description', N'上报工单的工单号',
'SCHEMA', N'dbo',
'TABLE', N'report_order',
'COLUMN', N'order_num'
GO

EXEC sp_addextendedproperty
'MS_Description', N'上报人名字',
'SCHEMA', N'dbo',
'TABLE', N'report_order',
'COLUMN', N'reporter'
GO

EXEC sp_addextendedproperty
'MS_Description', N'上报的工序id',
'SCHEMA', N'dbo',
'TABLE', N'report_order',
'COLUMN', N'report_process'
GO

EXEC sp_addextendedproperty
'MS_Description', N'上报的数量(不能超过工单总数量)',
'SCHEMA', N'dbo',
'TABLE', N'report_order',
'COLUMN', N'report_amount'
GO

EXEC sp_addextendedproperty
'MS_Description', N'上报时间',
'SCHEMA', N'dbo',
'TABLE', N'report_order',
'COLUMN', N'create_time'
GO

EXEC sp_addextendedproperty
'MS_Description', N'该工序执行人',
'SCHEMA', N'dbo',
'TABLE', N'report_order',
'COLUMN', N'process_worker'
GO

EXEC sp_addextendedproperty
'MS_Description', N'0代表还未结束，1代表结束',
'SCHEMA', N'dbo',
'TABLE', N'report_order',
'COLUMN', N'is_over'
GO

EXEC sp_addextendedproperty
'MS_Description', N'不良品数量',
'SCHEMA', N'dbo',
'TABLE', N'report_order',
'COLUMN', N'bad_amount'
GO

EXEC sp_addextendedproperty
'MS_Description', N'执行人工号',
'SCHEMA', N'dbo',
'TABLE', N'report_order',
'COLUMN', N'worker_no'
GO

EXEC sp_addextendedproperty
'MS_Description', N'0代表未缺，1代表缺了',
'SCHEMA', N'dbo',
'TABLE', N'report_order',
'COLUMN', N'is_missing'
GO

EXEC sp_addextendedproperty
'MS_Description', N'缺数（该条上报的缺数）',
'SCHEMA', N'dbo',
'TABLE', N'report_order',
'COLUMN', N'missing_amount'
GO

EXEC sp_addextendedproperty
'MS_Description', N'涉及机台',
'SCHEMA', N'dbo',
'TABLE', N'report_order',
'COLUMN', N'machine_num'
GO

EXEC sp_addextendedproperty
'MS_Description', N'材料编号/批号',
'SCHEMA', N'dbo',
'TABLE', N'report_order',
'COLUMN', N'stuff_num'
GO

EXEC sp_addextendedproperty
'MS_Description', N'CORE批号',
'SCHEMA', N'dbo',
'TABLE', N'report_order',
'COLUMN', N'core_num'
GO

EXEC sp_addextendedproperty
'MS_Description', N'部门id',
'SCHEMA', N'dbo',
'TABLE', N'report_order',
'COLUMN', N'dept_id'
GO

EXEC sp_addextendedproperty
'MS_Description', N'pinId',
'SCHEMA', N'dbo',
'TABLE', N'report_order',
'COLUMN', N'pin_id'
GO


-- ----------------------------
-- Table structure for sys_dept
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[sys_dept]') AND type IN ('U'))
	DROP TABLE [dbo].[sys_dept]
GO

CREATE TABLE [dbo].[sys_dept] (
  [id] int  IDENTITY(1,1) NOT NULL,
  [dept] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [erp_id] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL
)
GO

ALTER TABLE [dbo].[sys_dept] SET (LOCK_ESCALATION = TABLE)
GO

EXEC sp_addextendedproperty
'MS_Description', N'部门名称',
'SCHEMA', N'dbo',
'TABLE', N'sys_dept',
'COLUMN', N'dept'
GO

EXEC sp_addextendedproperty
'MS_Description', N'erpid',
'SCHEMA', N'dbo',
'TABLE', N'sys_dept',
'COLUMN', N'erp_id'
GO


-- ----------------------------
-- Table structure for sys_user
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[sys_user]') AND type IN ('U'))
	DROP TABLE [dbo].[sys_user]
GO

CREATE TABLE [dbo].[sys_user] (
  [id] int  IDENTITY(1,1) NOT NULL,
  [user_name] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [login_name] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [dept_id] int  NULL,
  [create_by] varchar(255) COLLATE Chinese_PRC_CI_AI DEFAULT 'admin' NULL,
  [create_time] datetime DEFAULT getdate() NULL,
  [password] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [type] char(1) COLLATE Chinese_PRC_CI_AI  NULL,
  [status] bit DEFAULT 1 NULL,
  [work_scope] varchar(255) COLLATE Chinese_PRC_CI_AI DEFAULT '0' NULL
)
GO

ALTER TABLE [dbo].[sys_user] SET (LOCK_ESCALATION = TABLE)
GO

EXEC sp_addextendedproperty
'MS_Description', N'用户姓名',
'SCHEMA', N'dbo',
'TABLE', N'sys_user',
'COLUMN', N'user_name'
GO

EXEC sp_addextendedproperty
'MS_Description', N'登录名（工号）',
'SCHEMA', N'dbo',
'TABLE', N'sys_user',
'COLUMN', N'login_name'
GO

EXEC sp_addextendedproperty
'MS_Description', N'部门id',
'SCHEMA', N'dbo',
'TABLE', N'sys_user',
'COLUMN', N'dept_id'
GO

EXEC sp_addextendedproperty
'MS_Description', N'创建者',
'SCHEMA', N'dbo',
'TABLE', N'sys_user',
'COLUMN', N'create_by'
GO

EXEC sp_addextendedproperty
'MS_Description', N'创建时间',
'SCHEMA', N'dbo',
'TABLE', N'sys_user',
'COLUMN', N'create_time'
GO

EXEC sp_addextendedproperty
'MS_Description', N'登录密码',
'SCHEMA', N'dbo',
'TABLE', N'sys_user',
'COLUMN', N'password'
GO

EXEC sp_addextendedproperty
'MS_Description', N'用户类型(1代表超级管理员，0代表二级权限，2代表普通操作员)',
'SCHEMA', N'dbo',
'TABLE', N'sys_user',
'COLUMN', N'type'
GO

EXEC sp_addextendedproperty
'MS_Description', N'1代表正在使用;0代表禁用',
'SCHEMA', N'dbo',
'TABLE', N'sys_user',
'COLUMN', N'status'
GO

EXEC sp_addextendedproperty
'MS_Description', N'作业工序,0代表无限制',
'SCHEMA', N'dbo',
'TABLE', N'sys_user',
'COLUMN', N'work_scope'
GO


-- ----------------------------
-- Table structure for sysdiagrams
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[sysdiagrams]') AND type IN ('U'))
	DROP TABLE [dbo].[sysdiagrams]
GO

CREATE TABLE [dbo].[sysdiagrams] (
  [name] sysname  NOT NULL,
  [principal_id] int  NOT NULL,
  [diagram_id] int  IDENTITY(1,1) NOT NULL,
  [version] int  NULL,
  [definition] varbinary(max)  NULL
)
GO

ALTER TABLE [dbo].[sysdiagrams] SET (LOCK_ESCALATION = TABLE)
GO


-- ----------------------------
-- Table structure for work_order
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[work_order]') AND type IN ('U'))
	DROP TABLE [dbo].[work_order]
GO

CREATE TABLE [dbo].[work_order] (
  [id] int  IDENTITY(1,1) NOT NULL,
  [order_num] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [create_time] datetime DEFAULT getdate() NULL,
  [product_type] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [material_code ] varchar(255) COLLATE Chinese_PRC_CI_AI DEFAULT '-' NULL,
  [material_name] varchar(255) COLLATE Chinese_PRC_CI_AI DEFAULT '-' NULL,
  [workshop] varchar(255) COLLATE Chinese_PRC_CI_AI DEFAULT '生产' NULL,
  [material_model] varchar(255) COLLATE Chinese_PRC_CI_AI DEFAULT '-' NULL,
  [amount] int DEFAULT 0 NULL,
  [unit] varchar(255) COLLATE Chinese_PRC_CI_AI DEFAULT '个' NULL,
  [process] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [now_process] int  NULL,
  [past_process] int DEFAULT 0 NULL,
  [next_process] int DEFAULT 0 NULL,
  [order_status] char(1) COLLATE Chinese_PRC_CI_AI DEFAULT 0 NULL,
  [now_worker] varchar(255) COLLATE Chinese_PRC_CI_AI DEFAULT '待定' NULL,
  [create_by] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [order_dept] int  NULL,
  [amount_plan] int  NULL,
  [over_process] varchar(255) COLLATE Chinese_PRC_CI_AI DEFAULT '0' NULL,
  [worker_no] varchar(255) COLLATE Chinese_PRC_CI_AI DEFAULT 0 NULL,
  [all_workers] varchar(255) COLLATE Chinese_PRC_CI_AI  NULL,
  [parent_id] int  NULL,
  [bad_amount] int DEFAULT 0 NULL,
  [create_now] datetime  NULL,
  [is_check] bit DEFAULT 0 NULL,
  [check_machine_id] int DEFAULT 0 NULL,
  [is_down] bit  NULL,
  [supply_amount] int DEFAULT 0 NULL,
  [pin_id] int  NULL
)
GO

ALTER TABLE [dbo].[work_order] SET (LOCK_ESCALATION = TABLE)
GO

EXEC sp_addextendedproperty
'MS_Description', N'工单编号',
'SCHEMA', N'dbo',
'TABLE', N'work_order',
'COLUMN', N'order_num'
GO

EXEC sp_addextendedproperty
'MS_Description', N'工单创建时间',
'SCHEMA', N'dbo',
'TABLE', N'work_order',
'COLUMN', N'create_time'
GO

EXEC sp_addextendedproperty
'MS_Description', N'产品类型',
'SCHEMA', N'dbo',
'TABLE', N'work_order',
'COLUMN', N'product_type'
GO

EXEC sp_addextendedproperty
'MS_Description', N'物料编码',
'SCHEMA', N'dbo',
'TABLE', N'work_order',
'COLUMN', N'material_code '
GO

EXEC sp_addextendedproperty
'MS_Description', N'物料名称',
'SCHEMA', N'dbo',
'TABLE', N'work_order',
'COLUMN', N'material_name'
GO

EXEC sp_addextendedproperty
'MS_Description', N'下达车间',
'SCHEMA', N'dbo',
'TABLE', N'work_order',
'COLUMN', N'workshop'
GO

EXEC sp_addextendedproperty
'MS_Description', N'物料型号规格',
'SCHEMA', N'dbo',
'TABLE', N'work_order',
'COLUMN', N'material_model'
GO

EXEC sp_addextendedproperty
'MS_Description', N'结算数量',
'SCHEMA', N'dbo',
'TABLE', N'work_order',
'COLUMN', N'amount'
GO

EXEC sp_addextendedproperty
'MS_Description', N'单位',
'SCHEMA', N'dbo',
'TABLE', N'work_order',
'COLUMN', N'unit'
GO

EXEC sp_addextendedproperty
'MS_Description', N'所需工序',
'SCHEMA', N'dbo',
'TABLE', N'work_order',
'COLUMN', N'process'
GO

EXEC sp_addextendedproperty
'MS_Description', N'当前工序id',
'SCHEMA', N'dbo',
'TABLE', N'work_order',
'COLUMN', N'now_process'
GO

EXEC sp_addextendedproperty
'MS_Description', N'上一工序id',
'SCHEMA', N'dbo',
'TABLE', N'work_order',
'COLUMN', N'past_process'
GO

EXEC sp_addextendedproperty
'MS_Description', N'下一工序id',
'SCHEMA', N'dbo',
'TABLE', N'work_order',
'COLUMN', N'next_process'
GO

EXEC sp_addextendedproperty
'MS_Description', N'工单状态，0代表工单进行中，1表示待审核,2工单结束',
'SCHEMA', N'dbo',
'TABLE', N'work_order',
'COLUMN', N'order_status'
GO

EXEC sp_addextendedproperty
'MS_Description', N'当前工序指派人员',
'SCHEMA', N'dbo',
'TABLE', N'work_order',
'COLUMN', N'now_worker'
GO

EXEC sp_addextendedproperty
'MS_Description', N'工单创建人',
'SCHEMA', N'dbo',
'TABLE', N'work_order',
'COLUMN', N'create_by'
GO

EXEC sp_addextendedproperty
'MS_Description', N'所属部门',
'SCHEMA', N'dbo',
'TABLE', N'work_order',
'COLUMN', N'order_dept'
GO

EXEC sp_addextendedproperty
'MS_Description', N'计划数量',
'SCHEMA', N'dbo',
'TABLE', N'work_order',
'COLUMN', N'amount_plan'
GO

EXEC sp_addextendedproperty
'MS_Description', N'已经完成的工序',
'SCHEMA', N'dbo',
'TABLE', N'work_order',
'COLUMN', N'over_process'
GO

EXEC sp_addextendedproperty
'MS_Description', N'委派人工号',
'SCHEMA', N'dbo',
'TABLE', N'work_order',
'COLUMN', N'worker_no'
GO

EXEC sp_addextendedproperty
'MS_Description', N'所有工序指派人（与工序顺序对应）',
'SCHEMA', N'dbo',
'TABLE', N'work_order',
'COLUMN', N'all_workers'
GO

EXEC sp_addextendedproperty
'MS_Description', N'父工单id',
'SCHEMA', N'dbo',
'TABLE', N'work_order',
'COLUMN', N'parent_id'
GO

EXEC sp_addextendedproperty
'MS_Description', N'结算不良数',
'SCHEMA', N'dbo',
'TABLE', N'work_order',
'COLUMN', N'bad_amount'
GO

EXEC sp_addextendedproperty
'MS_Description', N'流入当前工序的时间',
'SCHEMA', N'dbo',
'TABLE', N'work_order',
'COLUMN', N'create_now'
GO

EXEC sp_addextendedproperty
'MS_Description', N'当前工序是否checkin',
'SCHEMA', N'dbo',
'TABLE', N'work_order',
'COLUMN', N'is_check'
GO

EXEC sp_addextendedproperty
'MS_Description', N'检录机台id',
'SCHEMA', N'dbo',
'TABLE', N'work_order',
'COLUMN', N'check_machine_id'
GO

EXEC sp_addextendedproperty
'MS_Description', N'是否列票过',
'SCHEMA', N'dbo',
'TABLE', N'work_order',
'COLUMN', N'is_down'
GO

EXEC sp_addextendedproperty
'MS_Description', N'品名id',
'SCHEMA', N'dbo',
'TABLE', N'work_order',
'COLUMN', N'pin_id'
GO


-- ----------------------------
-- View structure for CPK未保存采样数据和规格数值的记录
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[CPK未保存采样数据和规格数值的记录]') AND type IN ('V'))
	DROP VIEW [dbo].[CPK未保存采样数据和规格数值的记录]
GO

CREATE VIEW [dbo].[CPK未保存采样数据和规格数值的记录] AS SELECT
	* 
FROM
	dbo.cpk_info 
WHERE
	dbo.cpk_info.s_data IS NULL 
	OR dbo.cpk_info.lsl IS NULL 
	OR dbo.cpk_info.usl IS NULL
GO


-- ----------------------------
-- View structure for 报工记录简易视图
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[报工记录简易视图]') AND type IN ('V'))
	DROP VIEW [dbo].[报工记录简易视图]
GO

CREATE VIEW [dbo].[报工记录简易视图] AS SELECT
	report_order.order_num, 
	report_order.report_process, 
	report_order.create_time
FROM
	dbo.report_order
WHERE create_time > '2023/02/01'
GO


-- ----------------------------
-- View structure for 电感正在使用的用户
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[电感正在使用的用户]') AND type IN ('V'))
	DROP VIEW [dbo].[电感正在使用的用户]
GO

CREATE VIEW [dbo].[电感正在使用的用户] AS SELECT
	* 
FROM
	sys_user 
WHERE
	dept_id = 3 
	AND status = '1'
GO


-- ----------------------------
-- View structure for 子工单简易视图
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[子工单简易视图]') AND type IN ('V'))
	DROP VIEW [dbo].[子工单简易视图]
GO

CREATE VIEW [dbo].[子工单简易视图] AS SELECT
	work_order.order_num, 
	work_order.create_time, 
	work_order.now_process
FROM
	dbo.work_order
GO


-- ----------------------------
-- function structure for fn_diagramobjects
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[fn_diagramobjects]') AND type IN ('FN', 'FS', 'FT', 'IF', 'TF'))
	DROP FUNCTION[dbo].[fn_diagramobjects]
GO

CREATE FUNCTION [dbo].[fn_diagramobjects]() 
	RETURNS int
	WITH EXECUTE AS N'dbo'
	AS
	BEGIN
		declare @id_upgraddiagrams		int
		declare @id_sysdiagrams			int
		declare @id_helpdiagrams		int
		declare @id_helpdiagramdefinition	int
		declare @id_creatediagram	int
		declare @id_renamediagram	int
		declare @id_alterdiagram 	int 
		declare @id_dropdiagram		int
		declare @InstalledObjects	int

		select @InstalledObjects = 0

		select 	@id_upgraddiagrams = object_id(N'dbo.sp_upgraddiagrams'),
			@id_sysdiagrams = object_id(N'dbo.sysdiagrams'),
			@id_helpdiagrams = object_id(N'dbo.sp_helpdiagrams'),
			@id_helpdiagramdefinition = object_id(N'dbo.sp_helpdiagramdefinition'),
			@id_creatediagram = object_id(N'dbo.sp_creatediagram'),
			@id_renamediagram = object_id(N'dbo.sp_renamediagram'),
			@id_alterdiagram = object_id(N'dbo.sp_alterdiagram'), 
			@id_dropdiagram = object_id(N'dbo.sp_dropdiagram')

		if @id_upgraddiagrams is not null
			select @InstalledObjects = @InstalledObjects + 1
		if @id_sysdiagrams is not null
			select @InstalledObjects = @InstalledObjects + 2
		if @id_helpdiagrams is not null
			select @InstalledObjects = @InstalledObjects + 4
		if @id_helpdiagramdefinition is not null
			select @InstalledObjects = @InstalledObjects + 8
		if @id_creatediagram is not null
			select @InstalledObjects = @InstalledObjects + 16
		if @id_renamediagram is not null
			select @InstalledObjects = @InstalledObjects + 32
		if @id_alterdiagram  is not null
			select @InstalledObjects = @InstalledObjects + 64
		if @id_dropdiagram is not null
			select @InstalledObjects = @InstalledObjects + 128
		
		return @InstalledObjects 
	END
GO


-- ----------------------------
-- procedure structure for sp_upgraddiagrams
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_upgraddiagrams]') AND type IN ('P', 'PC', 'RF', 'X'))
	DROP PROCEDURE[dbo].[sp_upgraddiagrams]
GO

CREATE PROCEDURE [dbo].[sp_upgraddiagrams]
	AS
	BEGIN
		IF OBJECT_ID(N'dbo.sysdiagrams') IS NOT NULL
			return 0;
	
		CREATE TABLE dbo.sysdiagrams
		(
			name sysname NOT NULL,
			principal_id int NOT NULL,	-- we may change it to varbinary(85)
			diagram_id int PRIMARY KEY IDENTITY,
			version int,
	
			definition varbinary(max)
			CONSTRAINT UK_principal_name UNIQUE
			(
				principal_id,
				name
			)
		);


		/* Add this if we need to have some form of extended properties for diagrams */
		/*
		IF OBJECT_ID(N'dbo.sysdiagram_properties') IS NULL
		BEGIN
			CREATE TABLE dbo.sysdiagram_properties
			(
				diagram_id int,
				name sysname,
				value varbinary(max) NOT NULL
			)
		END
		*/

		IF OBJECT_ID(N'dbo.dtproperties') IS NOT NULL
		begin
			insert into dbo.sysdiagrams
			(
				[name],
				[principal_id],
				[version],
				[definition]
			)
			select	 
				convert(sysname, dgnm.[uvalue]),
				DATABASE_PRINCIPAL_ID(N'dbo'),			-- will change to the sid of sa
				0,							-- zero for old format, dgdef.[version],
				dgdef.[lvalue]
			from dbo.[dtproperties] dgnm
				inner join dbo.[dtproperties] dggd on dggd.[property] = 'DtgSchemaGUID' and dggd.[objectid] = dgnm.[objectid]	
				inner join dbo.[dtproperties] dgdef on dgdef.[property] = 'DtgSchemaDATA' and dgdef.[objectid] = dgnm.[objectid]
				
			where dgnm.[property] = 'DtgSchemaNAME' and dggd.[uvalue] like N'_EA3E6268-D998-11CE-9454-00AA00A3F36E_' 
			return 2;
		end
		return 1;
	END
GO


-- ----------------------------
-- procedure structure for sp_helpdiagrams
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_helpdiagrams]') AND type IN ('P', 'PC', 'RF', 'X'))
	DROP PROCEDURE[dbo].[sp_helpdiagrams]
GO

CREATE PROCEDURE [dbo].[sp_helpdiagrams]
	(
		@diagramname sysname = NULL,
		@owner_id int = NULL
	)
	WITH EXECUTE AS N'dbo'
	AS
	BEGIN
		DECLARE @user sysname
		DECLARE @dboLogin bit
		EXECUTE AS CALLER;
			SET @user = USER_NAME();
			SET @dboLogin = CONVERT(bit,IS_MEMBER('db_owner'));
		REVERT;
		SELECT
			[Database] = DB_NAME(),
			[Name] = name,
			[ID] = diagram_id,
			[Owner] = USER_NAME(principal_id),
			[OwnerID] = principal_id
		FROM
			sysdiagrams
		WHERE
			(@dboLogin = 1 OR USER_NAME(principal_id) = @user) AND
			(@diagramname IS NULL OR name = @diagramname) AND
			(@owner_id IS NULL OR principal_id = @owner_id)
		ORDER BY
			4, 5, 1
	END
GO


-- ----------------------------
-- procedure structure for sp_helpdiagramdefinition
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_helpdiagramdefinition]') AND type IN ('P', 'PC', 'RF', 'X'))
	DROP PROCEDURE[dbo].[sp_helpdiagramdefinition]
GO

CREATE PROCEDURE [dbo].[sp_helpdiagramdefinition]
	(
		@diagramname 	sysname,
		@owner_id	int	= null 		
	)
	WITH EXECUTE AS N'dbo'
	AS
	BEGIN
		set nocount on

		declare @theId 		int
		declare @IsDbo 		int
		declare @DiagId		int
		declare @UIDFound	int
	
		if(@diagramname is null)
		begin
			RAISERROR (N'E_INVALIDARG', 16, 1);
			return -1
		end
	
		execute as caller;
		select @theId = DATABASE_PRINCIPAL_ID();
		select @IsDbo = IS_MEMBER(N'db_owner');
		if(@owner_id is null)
			select @owner_id = @theId;
		revert; 
	
		select @DiagId = diagram_id, @UIDFound = principal_id from dbo.sysdiagrams where principal_id = @owner_id and name = @diagramname;
		if(@DiagId IS NULL or (@IsDbo = 0 and @UIDFound <> @theId ))
		begin
			RAISERROR ('Diagram does not exist or you do not have permission.', 16, 1);
			return -3
		end

		select version, definition FROM dbo.sysdiagrams where diagram_id = @DiagId ; 
		return 0
	END
GO


-- ----------------------------
-- procedure structure for sp_creatediagram
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_creatediagram]') AND type IN ('P', 'PC', 'RF', 'X'))
	DROP PROCEDURE[dbo].[sp_creatediagram]
GO

CREATE PROCEDURE [dbo].[sp_creatediagram]
	(
		@diagramname 	sysname,
		@owner_id		int	= null, 	
		@version 		int,
		@definition 	varbinary(max)
	)
	WITH EXECUTE AS 'dbo'
	AS
	BEGIN
		set nocount on
	
		declare @theId int
		declare @retval int
		declare @IsDbo	int
		declare @userName sysname
		if(@version is null or @diagramname is null)
		begin
			RAISERROR (N'E_INVALIDARG', 16, 1);
			return -1
		end
	
		execute as caller;
		select @theId = DATABASE_PRINCIPAL_ID(); 
		select @IsDbo = IS_MEMBER(N'db_owner');
		revert; 
		
		if @owner_id is null
		begin
			select @owner_id = @theId;
		end
		else
		begin
			if @theId <> @owner_id
			begin
				if @IsDbo = 0
				begin
					RAISERROR (N'E_INVALIDARG', 16, 1);
					return -1
				end
				select @theId = @owner_id
			end
		end
		-- next 2 line only for test, will be removed after define name unique
		if EXISTS(select diagram_id from dbo.sysdiagrams where principal_id = @theId and name = @diagramname)
		begin
			RAISERROR ('The name is already used.', 16, 1);
			return -2
		end
	
		insert into dbo.sysdiagrams(name, principal_id , version, definition)
				VALUES(@diagramname, @theId, @version, @definition) ;
		
		select @retval = @@IDENTITY 
		return @retval
	END
GO


-- ----------------------------
-- procedure structure for sp_renamediagram
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_renamediagram]') AND type IN ('P', 'PC', 'RF', 'X'))
	DROP PROCEDURE[dbo].[sp_renamediagram]
GO

CREATE PROCEDURE [dbo].[sp_renamediagram]
	(
		@diagramname 		sysname,
		@owner_id		int	= null,
		@new_diagramname	sysname
	
	)
	WITH EXECUTE AS 'dbo'
	AS
	BEGIN
		set nocount on
		declare @theId 			int
		declare @IsDbo 			int
		
		declare @UIDFound 		int
		declare @DiagId			int
		declare @DiagIdTarg		int
		declare @u_name			sysname
		if((@diagramname is null) or (@new_diagramname is null))
		begin
			RAISERROR ('Invalid value', 16, 1);
			return -1
		end
	
		EXECUTE AS CALLER;
		select @theId = DATABASE_PRINCIPAL_ID();
		select @IsDbo = IS_MEMBER(N'db_owner'); 
		if(@owner_id is null)
			select @owner_id = @theId;
		REVERT;
	
		select @u_name = USER_NAME(@owner_id)
	
		select @DiagId = diagram_id, @UIDFound = principal_id from dbo.sysdiagrams where principal_id = @owner_id and name = @diagramname 
		if(@DiagId IS NULL or (@IsDbo = 0 and @UIDFound <> @theId))
		begin
			RAISERROR ('Diagram does not exist or you do not have permission.', 16, 1)
			return -3
		end
	
		-- if((@u_name is not null) and (@new_diagramname = @diagramname))	-- nothing will change
		--	return 0;
	
		if(@u_name is null)
			select @DiagIdTarg = diagram_id from dbo.sysdiagrams where principal_id = @theId and name = @new_diagramname
		else
			select @DiagIdTarg = diagram_id from dbo.sysdiagrams where principal_id = @owner_id and name = @new_diagramname
	
		if((@DiagIdTarg is not null) and  @DiagId <> @DiagIdTarg)
		begin
			RAISERROR ('The name is already used.', 16, 1);
			return -2
		end		
	
		if(@u_name is null)
			update dbo.sysdiagrams set [name] = @new_diagramname, principal_id = @theId where diagram_id = @DiagId
		else
			update dbo.sysdiagrams set [name] = @new_diagramname where diagram_id = @DiagId
		return 0
	END
GO


-- ----------------------------
-- procedure structure for sp_alterdiagram
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_alterdiagram]') AND type IN ('P', 'PC', 'RF', 'X'))
	DROP PROCEDURE[dbo].[sp_alterdiagram]
GO

CREATE PROCEDURE [dbo].[sp_alterdiagram]
	(
		@diagramname 	sysname,
		@owner_id	int	= null,
		@version 	int,
		@definition 	varbinary(max)
	)
	WITH EXECUTE AS 'dbo'
	AS
	BEGIN
		set nocount on
	
		declare @theId 			int
		declare @retval 		int
		declare @IsDbo 			int
		
		declare @UIDFound 		int
		declare @DiagId			int
		declare @ShouldChangeUID	int
	
		if(@diagramname is null)
		begin
			RAISERROR ('Invalid ARG', 16, 1)
			return -1
		end
	
		execute as caller;
		select @theId = DATABASE_PRINCIPAL_ID();	 
		select @IsDbo = IS_MEMBER(N'db_owner'); 
		if(@owner_id is null)
			select @owner_id = @theId;
		revert;
	
		select @ShouldChangeUID = 0
		select @DiagId = diagram_id, @UIDFound = principal_id from dbo.sysdiagrams where principal_id = @owner_id and name = @diagramname 
		
		if(@DiagId IS NULL or (@IsDbo = 0 and @theId <> @UIDFound))
		begin
			RAISERROR ('Diagram does not exist or you do not have permission.', 16, 1);
			return -3
		end
	
		if(@IsDbo <> 0)
		begin
			if(@UIDFound is null or USER_NAME(@UIDFound) is null) -- invalid principal_id
			begin
				select @ShouldChangeUID = 1 ;
			end
		end

		-- update dds data			
		update dbo.sysdiagrams set definition = @definition where diagram_id = @DiagId ;

		-- change owner
		if(@ShouldChangeUID = 1)
			update dbo.sysdiagrams set principal_id = @theId where diagram_id = @DiagId ;

		-- update dds version
		if(@version is not null)
			update dbo.sysdiagrams set version = @version where diagram_id = @DiagId ;

		return 0
	END
GO


-- ----------------------------
-- procedure structure for sp_dropdiagram
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_dropdiagram]') AND type IN ('P', 'PC', 'RF', 'X'))
	DROP PROCEDURE[dbo].[sp_dropdiagram]
GO

CREATE PROCEDURE [dbo].[sp_dropdiagram]
	(
		@diagramname 	sysname,
		@owner_id	int	= null
	)
	WITH EXECUTE AS 'dbo'
	AS
	BEGIN
		set nocount on
		declare @theId 			int
		declare @IsDbo 			int
		
		declare @UIDFound 		int
		declare @DiagId			int
	
		if(@diagramname is null)
		begin
			RAISERROR ('Invalid value', 16, 1);
			return -1
		end
	
		EXECUTE AS CALLER;
		select @theId = DATABASE_PRINCIPAL_ID();
		select @IsDbo = IS_MEMBER(N'db_owner'); 
		if(@owner_id is null)
			select @owner_id = @theId;
		REVERT; 
		
		select @DiagId = diagram_id, @UIDFound = principal_id from dbo.sysdiagrams where principal_id = @owner_id and name = @diagramname 
		if(@DiagId IS NULL or (@IsDbo = 0 and @UIDFound <> @theId))
		begin
			RAISERROR ('Diagram does not exist or you do not have permission.', 16, 1)
			return -3
		end
	
		delete from dbo.sysdiagrams where diagram_id = @DiagId;
	
		return 0;
	END
GO


-- ----------------------------
-- Auto increment value for all_machine
-- ----------------------------
DBCC CHECKIDENT ('[dbo].[all_machine]', RESEED, 16)
GO


-- ----------------------------
-- Primary Key structure for table all_machine
-- ----------------------------
ALTER TABLE [dbo].[all_machine] ADD CONSTRAINT [PK__all_mach__3213E83FC1389258] PRIMARY KEY CLUSTERED ([id])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Auto increment value for check_info
-- ----------------------------
DBCC CHECKIDENT ('[dbo].[check_info]', RESEED, 1)
GO


-- ----------------------------
-- Primary Key structure for table check_info
-- ----------------------------
ALTER TABLE [dbo].[check_info] ADD CONSTRAINT [PK__check_in__3213E83F33C11B71] PRIMARY KEY CLUSTERED ([id])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Auto increment value for complement_info
-- ----------------------------
DBCC CHECKIDENT ('[dbo].[complement_info]', RESEED, 1)
GO


-- ----------------------------
-- Primary Key structure for table complement_info
-- ----------------------------
ALTER TABLE [dbo].[complement_info] ADD CONSTRAINT [PK__compleme__3213E83FFB21D940] PRIMARY KEY CLUSTERED ([id])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Auto increment value for core_library
-- ----------------------------
DBCC CHECKIDENT ('[dbo].[core_library]', RESEED, 9)
GO


-- ----------------------------
-- Primary Key structure for table core_library
-- ----------------------------
ALTER TABLE [dbo].[core_library] ADD CONSTRAINT [PK__core_lib__3213E83FDB2CD32D] PRIMARY KEY CLUSTERED ([id])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Auto increment value for cpk_info
-- ----------------------------
DBCC CHECKIDENT ('[dbo].[cpk_info]', RESEED, 5215)
GO


-- ----------------------------
-- Primary Key structure for table cpk_info
-- ----------------------------
ALTER TABLE [dbo].[cpk_info] ADD CONSTRAINT [PK__cpk_info__3213E83FFBF5CFCB] PRIMARY KEY CLUSTERED ([id])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Auto increment value for delete_info
-- ----------------------------
DBCC CHECKIDENT ('[dbo].[delete_info]', RESEED, 596)
GO


-- ----------------------------
-- Primary Key structure for table delete_info
-- ----------------------------
ALTER TABLE [dbo].[delete_info] ADD CONSTRAINT [PK__delete_i__3213E83F06DFE92D] PRIMARY KEY CLUSTERED ([id])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Auto increment value for in_storage
-- ----------------------------
DBCC CHECKIDENT ('[dbo].[in_storage]', RESEED, 1)
GO


-- ----------------------------
-- Primary Key structure for table in_storage
-- ----------------------------
ALTER TABLE [dbo].[in_storage] ADD CONSTRAINT [PK__in_stora__3213E83F02C95596] PRIMARY KEY CLUSTERED ([id])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Auto increment value for machine_info
-- ----------------------------
DBCC CHECKIDENT ('[dbo].[machine_info]', RESEED, 2009)
GO


-- ----------------------------
-- Primary Key structure for table machine_info
-- ----------------------------
ALTER TABLE [dbo].[machine_info] ADD CONSTRAINT [PK__machine___3213E83F14B6DFB3] PRIMARY KEY CLUSTERED ([id])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Auto increment value for out_storage
-- ----------------------------
DBCC CHECKIDENT ('[dbo].[out_storage]', RESEED, 1)
GO


-- ----------------------------
-- Primary Key structure for table out_storage
-- ----------------------------
ALTER TABLE [dbo].[out_storage] ADD CONSTRAINT [PK__out_stor__3213E83F1F126CB7] PRIMARY KEY CLUSTERED ([id])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Auto increment value for parent_order
-- ----------------------------
DBCC CHECKIDENT ('[dbo].[parent_order]', RESEED, 100)
GO


-- ----------------------------
-- Primary Key structure for table parent_order
-- ----------------------------
ALTER TABLE [dbo].[parent_order] ADD CONSTRAINT [PK__parent_o__3213E83FF3520439] PRIMARY KEY CLUSTERED ([id])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Auto increment value for pin_library
-- ----------------------------
DBCC CHECKIDENT ('[dbo].[pin_library]', RESEED, 11)
GO


-- ----------------------------
-- Primary Key structure for table pin_library
-- ----------------------------
ALTER TABLE [dbo].[pin_library] ADD CONSTRAINT [PK__product___3213E83FDF627514] PRIMARY KEY CLUSTERED ([id])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Auto increment value for process_condition
-- ----------------------------
DBCC CHECKIDENT ('[dbo].[process_condition]', RESEED, 15)
GO


-- ----------------------------
-- Primary Key structure for table process_condition
-- ----------------------------
ALTER TABLE [dbo].[process_condition] ADD CONSTRAINT [PK__process___3213E83F50E40407] PRIMARY KEY CLUSTERED ([id])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Auto increment value for process_info
-- ----------------------------
DBCC CHECKIDENT ('[dbo].[process_info]', RESEED, 2014)
GO


-- ----------------------------
-- Primary Key structure for table process_info
-- ----------------------------
ALTER TABLE [dbo].[process_info] ADD CONSTRAINT [PK__process___3213E83FDCD96F14] PRIMARY KEY CLUSTERED ([id])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Auto increment value for re_order
-- ----------------------------
DBCC CHECKIDENT ('[dbo].[re_order]', RESEED, 1)
GO


-- ----------------------------
-- Primary Key structure for table re_order
-- ----------------------------
ALTER TABLE [dbo].[re_order] ADD CONSTRAINT [PK__re_order__3213E83F961D625A] PRIMARY KEY CLUSTERED ([id])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Auto increment value for report_order
-- ----------------------------
DBCC CHECKIDENT ('[dbo].[report_order]', RESEED, 177656)
GO


-- ----------------------------
-- Primary Key structure for table report_order
-- ----------------------------
ALTER TABLE [dbo].[report_order] ADD CONSTRAINT [PK__report_o__3213E83F61B8BBEC] PRIMARY KEY CLUSTERED ([id])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Auto increment value for sys_dept
-- ----------------------------
DBCC CHECKIDENT ('[dbo].[sys_dept]', RESEED, 1004)
GO


-- ----------------------------
-- Primary Key structure for table sys_dept
-- ----------------------------
ALTER TABLE [dbo].[sys_dept] ADD CONSTRAINT [PK__dept__3213E83FCBE34A32] PRIMARY KEY CLUSTERED ([id])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Auto increment value for sys_user
-- ----------------------------
DBCC CHECKIDENT ('[dbo].[sys_user]', RESEED, 2106)
GO


-- ----------------------------
-- Primary Key structure for table sys_user
-- ----------------------------
ALTER TABLE [dbo].[sys_user] ADD CONSTRAINT [PK__sys_user__3213E83F8ED5DB39] PRIMARY KEY CLUSTERED ([id])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Auto increment value for sysdiagrams
-- ----------------------------
DBCC CHECKIDENT ('[dbo].[sysdiagrams]', RESEED, 1)
GO


-- ----------------------------
-- Uniques structure for table sysdiagrams
-- ----------------------------
ALTER TABLE [dbo].[sysdiagrams] ADD CONSTRAINT [UK_principal_name] UNIQUE NONCLUSTERED ([principal_id] ASC, [name] ASC)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Primary Key structure for table sysdiagrams
-- ----------------------------
ALTER TABLE [dbo].[sysdiagrams] ADD CONSTRAINT [PK__sysdiagr__C2B05B615827D862] PRIMARY KEY CLUSTERED ([diagram_id])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Auto increment value for work_order
-- ----------------------------
DBCC CHECKIDENT ('[dbo].[work_order]', RESEED, 39369)
GO


-- ----------------------------
-- Primary Key structure for table work_order
-- ----------------------------
ALTER TABLE [dbo].[work_order] ADD CONSTRAINT [PK__work_ord__3213E83FCC52CE22] PRIMARY KEY CLUSTERED ([id])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO

